<?php
/**
 * TinyMVC - TinyMVCRequest.class.php file
 * 
 * @author Adrian Wieczorek <adi(at)tinymvc(dot)org>
 * @package TinyMVC
 * @version $Id: TinyMVCRequest.class.php 10 2007-09-28 19:55:12Z adi3ek $
 * 
 */ 

/**
 * Request abstract class
 * @package TinyMVC
 */
abstract class TinyMVCRequest {
	protected $paramArray;
	protected $sessionArray;
	static protected $instance = null;
	
	private function __construct() {
	}
	
	final private function __clone() {
	}
				
	/**
	 * get parameter value by given key
	 * @param string $key parameter key
	 * @param mixed $nullValue return value for non-existent key
	 * @return mixed parametr value
	 */
	public function getParam($key, $nullValue = null) {
		return array_key_exists($key, $this->paramArray) ? $this->paramArray[$key] : $nullValue;
	}
	
	/**
	 * set parameter value
	 * @param string $key parameter key
	 * @param mixed $value parameter value
	 */
	public function setParam($key, $value) {
		$this->paramArray[$key] = $value;
	}
	
	/**
	 * get session parameter value by given key
	 * @param string $key session key
	 * @param mixed $nullValue return value for non-existent key	
	 * @return mixed session value
	 */
	public function getSessionParam($key, $nullValue = null) {
		return array_key_exists($key, $this->sessionArray) ? $this->sessionArray[$key] : $nullValue;					
	}
  
	/**
	 * check whether or not session is registered 
	 * @param string $key session key
	 * @return bool 
	 */
	public function isSessionRegistered($key) {
		return array_key_exists($key, $this->sessionArray[$key]) ? true : false;
	}
	
	/**
	 * set session parameter
	 * @param string $key session key
	 * @param mixed $value session value 
	 */
	public function setSessionParam($key, $value) {
		$this->sessionArray[$key] = $value;
	}
		
	/**
	 * remove session parameter by key
	 * @param string $key session key
	 */
	public function sessionUnregister($key) {
		unset($this->sessionArray[$key]);
	}

	/**
	 * get all parameters
	 * @return array key => value parameters array
	 */
	public function getParams() {
		return $this->paramArray;
	}
	
	/**
	 * get all sessions
	 * @return array key => value session parameters array
	 */
	public function getSessions() {
		return $this->sessionArray;
	}
}
